package com.test;

/**
 * @name 菠菜
 * @date 2024-06-13 16:24
 */
public class MyArr {
    public void main() {
        int[] arr = {4, 5, 6, 1, 9};
        //找最大值
        int max = arr[0];
        for (int i = 1; i < arr.length; i++) {//此处i从1开始，是max不需要与arr[0]再比较一次了
            if (arr[i] > max) {
                max = arr[i];
            }
        }

        System.out.println("max = " + max);
    }

    public void main2() {
        int[] arr = {9, 15, 13, 44, 25, 3, 4, 6,1 };
        int min = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] < min) {
                min = arr[i];
            }
        }
        System.out.println("min的最小值是 = " + min);

    }

    public void main3() {
        int [] arr = {1,2,3,4,5,6,7,8,9,10};
//        找最大值和最小值
        int max = arr[0];
        int index = 0;
        for (int i=1; i<arr.length; i++){
            if (arr[i]>max){
                max = arr[i];
                index = i;
            }
        }
        System.out.println("最大值是 = " + max + "下标是 = " + index);

    }
}




